package ${packageName}.admin.controller;

import ${packageName}.model.${modelName};
import ${packageName}.admin.service.${serviceName};
import com.ailanyin.common.result.AjaxResult;
import com.ailanyin.common.result.CommonPage;
import com.github.pagehelper.PageHelper;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
* @author ailanyin
* @version 1.0
* @since ${.now?string('yyyy-MM-dd hh:mm:ss')}
*/
@RestController
@RequestMapping("/business/${modelName}")
@Api(tags = "${remarks}管理")
public class ${controllerName}{

    @Autowired
    private ${serviceName} ${serviceName?uncap_first};

	@PostMapping
    @ApiOperation(value = "新增('business:${modelName?uncap_first}:add')")
    @PreAuthorize("hasAuthority('business:${modelName?uncap_first}:add')")
    public AjaxResult insert${modelName}(@RequestBody ${modelName} ${modelName?uncap_first}) {
        ${serviceName?uncap_first}.insert${modelName}(${modelName?uncap_first});
        return AjaxResult.success();
    }

    @PutMapping
    @ApiOperation(value = "修改('business:${modelName?uncap_first}:edit')")
    @PreAuthorize("hasAuthority('business:${modelName?uncap_first}:edit')")
    public AjaxResult update${modelName}(@RequestBody ${modelName} ${modelName?uncap_first}) {
        ${serviceName?uncap_first}.update${modelName}(${modelName?uncap_first});
        return AjaxResult.success();
    }

    @DeleteMapping("/{ids}")
    @ApiOperation(value = "批量删除('business:${modelName?uncap_first}:remove')")
    @PreAuthorize("hasAuthority('business:${modelName?uncap_first}:remove')")
    public AjaxResult deleteByIds(@PathVariable Long[] ids) {
        ${serviceName?uncap_first}.deleteByIds(ids);
        return AjaxResult.success();
    }

    @GetMapping("/list")
    @ApiOperation(value = "获取列表('business:${modelName?uncap_first}:list')")
    @PreAuthorize("hasAuthority('business:${modelName?uncap_first}:list')")
    public CommonPage list(${modelName} ${modelName?uncap_first},
                           @RequestParam(value = "pageSize", defaultValue = "5") Integer pageSize,
                           @RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum) {
        PageHelper.startPage(pageNum, pageSize);
        List<${modelName}> list = ${serviceName?uncap_first}.getListByParam(${modelName?uncap_first});
        return CommonPage.restPage(list);
    }

    @GetMapping(value = {"/{id}"})
    @ApiOperation(value = "根据id获取详情('business:${modelName?uncap_first}:query')")
    @PreAuthorize("hasAuthority('business:${modelName?uncap_first}:query')")
    public AjaxResult getInfo(@PathVariable(value = "id", required = false) Long id) {
        return AjaxResult.success(${serviceName?uncap_first}.getInfo(id));
    }
}
